package com.hanyxx.thread.lambda;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author layman
 */
public class Demo03 {
    public static void main(String[] args) {
        //存入怪物数组
        Monster[] monsters = {
                new Monster("虚空怪物",300),
                new Monster("触手蟑螂",45),
                new Monster("铁头鱼",458)};

        System.out.println("排序前：" + Arrays.toString(monsters));

        Arrays.sort(monsters, new Comparator<Monster>() {

            @Override
            public int compare(Monster o1, Monster o2) {
                return 0;
            }
        });
        //使用Lambda表达式编写函数接口
        Arrays.sort(monsters,(o1,o2)->{
            return o2.getAge() - o1.getAge();
        });
        System.out.println("排序后：" + Arrays.toString(monsters));
    }
}
@Data
@AllArgsConstructor
class Monster{
    private String name;
    private Integer age;
}
